package com.eco.fanliapp.controller.app;


import com.eco.fanliapp.common.base.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.entity.SyUserMoney;
import com.eco.fanliapp.service.IAppUserService;
import com.eco.fanliapp.service.ISyUserMoneyService;
import com.eco.fanliapp.service.ISyUserTaskService;
import lombok.Synchronized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-08-07
 */
@RestController
@RequestMapping("/app/task")
public class SyUserMoneyController extends BaseController {

    @Autowired
    private ISyUserMoneyService iSyUserMoneyService;
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private ISyUserTaskService iSyUserTaskService;

    /**
     * 现金金额，可兑换金币
     *
     * @return
     */
    @GetMapping("/money/list")
    public ServerResponse getAppTaskMoneyList() {
        AppUser u = getAppUser();
        if (null == u) {
            return ServerResponse.createByErrorCodeMessage(301, "Token不正确");
        }
        return iSyUserMoneyService.getAppTaskMoneyList(u.getUserId());
    }


    /**
     * 现金收入明细
     *
     * @return
     */
    @GetMapping("cash/incomeDetails")
    @ResponseBody
    public ServerResponse cashIncomeDetails(Integer pageNum, Integer pageSize) throws ParseException {
        AppUser u = getAppUser();
        if (u == null || u.getUserId() == null) {
            return ServerResponse.createBySuccessCodeMessage(301, "用户不存在");
        }
        AppUser appUser = appUserService.selectAppUserByUserId(u.getUserId());
        if (appUser == null || appUser.getUserId() == null) {
            return ServerResponse.createBySuccessCodeMessage(301, "用户不存在");
        } else {
            return iSyUserTaskService.cashIncomeDetails(pageNum, pageSize, appUser.getUserId());
        }
    }

    /**
     * 金币收益明细
     *
     * @return
     */
    @GetMapping("gold/incomeDetails")
    @ResponseBody
    public ServerResponse goldIncomeDetails(Integer pageNum, Integer pageSize) {
        AppUser u = getAppUser();
        if (u == null || u.getUserId() == null) {
            return ServerResponse.createBySuccessCodeMessage(301, "用户不存在");
        }
        AppUser appUser = appUserService.selectAppUserByUserId(u.getUserId());
        if (appUser == null || appUser.getUserId() == null) {
            return ServerResponse.createBySuccessCodeMessage(301, "用户不存在");
        } else {
            return iSyUserTaskService.goldIncomeDetails(pageNum, pageSize, appUser.getUserId());
        }
    }

    /**
     * 创建userMoney
     *
     * @return
     */
    @GetMapping("user/createUserMonye")
    @ResponseBody
    public ServerResponse selectUserIdCreateUserMonye() {

        return iSyUserTaskService.selectUserIdCreateUserMonye();
    }


    @GetMapping("/getGoldNum")
    @ResponseBody
    public ServerResponse getGoldNum() {
        AppUser user = getAppUser();
        if (null == user) {
            return ServerResponse.createByErrorCodeMessage(301, "Token不正确");
        }
        return iSyUserMoneyService.getGoldNum(user.getUserId());
    }

}
